package 哈希;

import java.util.*;

/**
 * @author tmh
 * @date 2025/3/6 17:00
 * @description
 */
public class T49字母异位词分组 {
    public static void main(String[] args) {

    }
    public List<List<String>> groupAnagrams(String[] strs) {
        List<List<String>> result = new ArrayList<>();
        Map<String,List<String>> map =new HashMap<>();
        for (String str : strs) {
            char[] charArray = str.toCharArray();
            Arrays.sort(charArray);
            String temp = new String(charArray);
            List<String> list = map.getOrDefault(temp, new ArrayList<>());
            list.add(str);
            map.put(temp,list);
        }
        return new ArrayList<>(map.values());

    }
}
